package org.sensmon.gui;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.DefaultListModel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JList;
import javax.swing.ListSelectionModel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JScrollPane;
import javax.swing.JCheckBoxMenuItem;

import org.sensmon.core.GUIThread;

import javax.swing.border.LineBorder;
import javax.swing.UIManager;


public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	
	private JPanel contentPane;
	private JList<SensorPane> list;
	
	/**
	 * Create the frame.
	 */
	public MainFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		final DefaultListModel<SensorPane> model = new DefaultListModel<SensorPane>();
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		JMenuItem mntmOptions = new JMenuItem("Options");
		mntmOptions.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GUIThread.getInstance().getOptionsFrame().setVisible(true);
			}
		});
		mnFile.add(mntmOptions);
		
		mnFile.addSeparator();
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		mnFile.add(mntmExit);
		
		JMenu mnActions = new JMenu("Actions");
		menuBar.add(mnActions);
		
		JMenuItem mntmAddSensor = new JMenuItem("Add sensor");
		mntmAddSensor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// some
			}
		});

		mnActions.add(mntmAddSensor);
		
		mnActions.addSeparator();
		
		final JCheckBoxMenuItem chckbxmntmRun = new JCheckBoxMenuItem("Run");
		chckbxmntmRun.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// some
			}
		});
		
		mnActions.add(chckbxmntmRun);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		list = new JList<SensorPane>(model);
		list.setBorder(null);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setCellRenderer(new SensorPaneListRenderer());
		JScrollPane scrollPane = new JScrollPane(list);
		scrollPane.setViewportBorder(new LineBorder(UIManager.getColor("textHighlight"), 2, true));
		contentPane.add(scrollPane, BorderLayout.CENTER);
		setVisible(true);
	}

}
